package component.fy.com.common_module.widget;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by Administrator on 2017/6/19 0019.
 * recyclerview的分隔线
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int left;
    private int right;
    private int top;
    private int bottom;

    public SpaceItemDecoration(int left, int top, int right, int bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        //不是第一个的格子都设一个左边和底部的间距
        outRect.left = left;
        outRect.top = top;
        outRect.right = right;
        /*//由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
        if (parent.getChildLayoutPosition(view) %3==0) {
            outRect.left = 0;
        }*/
        if (parent.getChildAdapterPosition(view) == parent.getLayoutManager().getItemCount() - 1) {
            outRect.bottom = 0;
        } else {
            outRect.bottom = bottom;
        }
    }
}
